package com.awesome.ipcdemo.aidl;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;

import androidx.annotation.Nullable;

import com.awesome.ipcdemo.IGameManenger;
import com.awesome.ipcdemo.aidl.bean.Game;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * Author: zhangjingfang
 * Email:zhangjingfang@jeejio.com
 * Date: 2021/8/8 11:27 下午
 * Description:服务端
 */
public class AIDLService extends Service {
    private CopyOnWriteArrayList<String> mGameList = new CopyOnWriteArrayList<>();

    Binder mBinder = new IGameManenger.Stub() {

        @Override
        public List<String> getGameList() throws RemoteException {
            return mGameList;
        }

        @Override
        public void addGame(String game) throws RemoteException {
            mGameList.add(game);
        }
    };

    @Override
    public void onCreate() {
        super.onCreate();
        mGameList.add("九阴真经ol 最好玩的武侠网游");
        mGameList.add("大航海时代ol 最好玩的航海网游");
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return mBinder;
    }
}